﻿#if Profile && TRUNKTQ
using System;
using System.Collections.Concurrent;
using System.Diagnostics;
using System.Transactions;
using O1.Kernel;
using O1.Kernel.Primitives;
using O1.Kernel.Storage;
using O1.Kernel.Storage.Transactions;

namespace O1.Profiling
{
    class Program
    {
        private const int size = 1024 * 102;

        private static readonly byte[] newCell = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };

        static void Main(string[] args)
        {
            var trunk = new MemoryTrunk(size, 0);
            for (int i = 0; i < size; i++)
            {
                using (var token = new ConcurrentScope())
                {
                    trunk.AllocateVertex(newCell, token);
                    trunk.TryCommit(token);
                }
            }

            // Quirk, 1 based indexing and 0 is empty. This is OK, possibly desirable. It allows 0 to 
            // mean 'uninitialized' when referring to a cell address.
            for (int i = 1; i < size + 1; i++)
            {
                using (var token = new ConcurrentScope())
                {
                    var newVersion = trunk.ReadVertex(i, token);
                    trunk.WriteVertex(i, newVersion, token);
                    trunk.TryCommit(token);
                }
            }
        }
    }
}
#endif